<?php
declare (strict_types = 1);

namespace app\validate;

use think\Validate;

class Users extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'nickname'=>['require'],
        'mobile'=>['require','isMobile' => '/^1[3-9]\d{9}$/','checkPhone:thinkphp'],
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [
        'nickname.require'=>'用户名称不能为空',
        'mobile.require'=>'手机号不能为空',
        'mobile.isMobile'=>'手机号格式不正确',
        'mobile.checkPhone'=>'此手机号已被注册'
    ];
    protected function checkPhone($value,$rule,$data= []):bool{
        $id='';
        if(isset($data['id']) && !empty($data['id'])){
            $id= $data['id'];
        }
        $service = app('app\service\checkField');
        return $service->accountCheckPhone($value,$id);
    }
}
